import Vue from 'vue'
import App from './App'
import axios from 'axios'
import store from './store/index'
import router from './router'
import Mint from 'mint-ui'
import {Indicator} from 'mint-ui'

Vue.use(Mint)
Vue.prototype.$http = axios

Vue.config.productionTip = false
axios.interceptors.request.use(function(config) { //axios拦截器
	Indicator.open('加载中...');
	return config;
})
axios.interceptors.response.use(function(config) {
	// setTimeout(() => {
	Indicator.close();
	// }, 300)
	return config;

})
router.beforeEach((to, from, next) => {
	const publicList = ['/login', '/register']
	if (publicList.indexOf(to.path) > -1) {
		next()
	} else {
		axios('/api/user/info').then(res => {
			console.log(res)
			if (res.status == 200) {
				if (res.data.code == 0) {
					//有登录信息
					next()
				} else {
					router.push('login')
				}
			}

		})

	}

})

/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	store,
	render: h => h(App)
})
